package com.itheima.mapper;


import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ClazzMapper {

    /**
     * 查询所有班级
     */
     /*@Select("select id, name, room, begin_date, end_date, master_id, subject, create_time, update_time from clazz;")*/
    List<Clazz> selectAllClazz(ClazzQueryParam clazzQueryParam);

    @Insert("INSERT INTO clazz(id, name, room, begin_date, end_date, master_id, subject, create_time, update_time) VALUES (#{id},#{name},#{room},#{beginDate},#{endDate},#{masterId},#{subject},#{createTime},#{updateTime})")
    void addClazz(Clazz clazz);

    /**
     * 根据id查询班级
     * @param id 接收前端传回来的id
     * @return
     */
    @Select("select id, name, room, begin_date, end_date, master_id, subject, create_time, update_time from clazz where id=#{id}")
    Clazz getByIdClazz(Integer  id);

    /**
     *删除班级
     */
    @Delete("delete from clazz where id=#{id};")
    void deleteById(Integer id);

    void updateClazz(Clazz clazz);

    /**
     * 查询所在班级是否有学生
     * @param id
     */
    @Select("select count(*) from clazz c left join student s on c.id = s.clazz_id where s.clazz_id=#{id}")
    Integer selectCount(Integer id);

    /**
     * 查询学员管理中条件查询中的所有班级
     */
    @Select("select * from clazz;")
    List<Clazz> findAll();
}
